<?php
class Animus_home extends Animus_FrontEnd_Controller{
	function Animus_home(){
		parent :: Animus_FrontEnd_Controller();
		$this->load->model('home/annonce/Animus_home_annonce');
	}
	function index(){
		$this->display_view('home/index');
	}
	
	function list_all_annonces(){
		$per_page = $this->uri->segment(3) != '' ? $this->uri->segment(3) : 5;
		$off_set = $this->uri->segment(4) != '' ? $this->uri->segment(4) : 0;
		$config['base_url'] = base_url() . 'index.php/animus_home/list_all_annonces/' . $per_page . '/';
		$config['per_page'] = 5;
		$config['uri_segment'] = 4;
		$config['total_rows'] = $this->Animus_home_annonce->count_annonce();
		$this->_data['count_all_annonce'] = $config['total_rows'];
		if ($config['total_rows'] == $off_set && $off_set > 0) {
            $off_set = $off_set - $per_page;
        }
        $result = $this->Animus_home_annonce->get_all_annonces($per_page, $off_set);
		$this->_data['annonces'] = $result;
		$this->_data['per_page'] = $per_page;
        $this->_data['off_set'] =$off_set;
        $this->pagination->initialize($config);
        $this->_data['pagination'] = $this->pagination->create_links();
	 	$this->display_view('/');
	}
	
	function list_gratuitement_annonces(){
		$per_page = $this->uri->segment(3) != '' ? $this->uri->segment(3) : 5;
		$off_set = $this->uri->segment(4) != '' ? $this->uri->segment(4) : 0;
		$config['base_url'] = base_url() . 'index.php/animus_home/list_gratuitement_annonces/' . $per_page . '/';
		$config['per_page'] = 5;
		$config['uri_segment'] = 4;
		$gratuitement_level = 1;
		$config['total_rows'] = $this->Animus_home_annonce->count_annonce($gratuitement_level);
		$this->_data['count_all_annonce'] = $config['total_rows'];
		if ($config['total_rows'] == $off_set && $off_set > 0) {
            $off_set = $off_set - $per_page;
        }
        $result = $this->Animus_home_annonce->get_annonces_by_level($gratuitement_level,$per_page, $off_set);
		$this->_data['annonces'] =  $result;
		$this->_data['per_page'] =  $per_page;
        $this->_data['off_set']  =  $off_set;
        $this->pagination->initialize($config);
        $this->_data['pagination'] = $this->pagination->create_links();
	 	//$this->display_view('home/sidebar_left');
	 
	}
	
	function list_premium_annonces(){
		$per_page = $this->uri->segment(3) != '' ? $this->uri->segment(3) : 5;
		$off_set = $this->uri->segment(4) != '' ? $this->uri->segment(4) : 0;
		$config['base_url'] = base_url() . 'index.php/animus_home/list_premium_annonces/' . $per_page . '/';
		$config['per_page'] = 5;
		$config['uri_segment'] = 4;
		$gratuitement_level = 2;
		$config['total_rows'] = $this->Animus_home_annonce->count_annonce($gratuitement_level);
		$this->_data['count_all_annonce'] = $config['total_rows'];
		if ($config['total_rows'] == $off_set && $off_set > 0) {
            $off_set = $off_set - $per_page;
        }
        $result = $this->Animus_home_annonce->get_annonces_by_level($gratuitement_level,$per_page, $off_set);
		$this->_data['annonces'] =  $result;
		$this->_data['per_page'] =  $per_page;
        $this->_data['off_set']  =  $off_set;
        $this->pagination->initialize($config);
        $this->_data['pagination'] = $this->pagination->create_links();
	 	//$this->display_view('home/annonce/list_premium_annonces');
	 
	}
	
	function annonce_details($id){
		$this->_data['annonce_details'] = $this->Animus_home_annonce->get_annonce_details($id);
		$this->display_view('home/annonce/annonce_details');	
	}
	
	function actualite_details($id){
		$this->_data['actualite_details'] = $this->Animus_home_m->get_actualite_details($id);
		$this->display_view('home/actualite/actualite_details');
	}
	
	function list_annonce(){
		$per_page = $this->uri->segment(3) != '' ? $this->uri->segment(3) : 6;
		$off_set = $this->uri->segment(4) != '' ? $this->uri->segment(4) : 0;
		$config['base_url'] = base_url() . 'index.php/animus_home/list_annonce/' . $per_page . '/';
		$config['per_page'] = 6;
		$config['uri_segment'] = 4;
		$config['total_rows'] = $this->Animus_home_annonce->count_annonce();
		$this->_data['count_all_annonce'] = $config['total_rows'];
		if ($config['total_rows'] == $off_set && $off_set > 0) {
            $off_set = $off_set - $per_page;
        }
        $result = $this->Animus_home_annonce->list_home_annonces($per_page, $off_set);
		$this->_data['annonces'] =  $result;
		$this->_data['per_page'] =  $per_page;
        $this->_data['off_set']  =  $off_set;
        $this->pagination->initialize($config);
        $this->_data['pagination'] = $this->pagination->create_links();
        $this->_data['is_list'] = TRUE;
		$this->display_view('home/index');
		
	}

        function detail_card_vip() {
        $query = $this->Animus_home_m->get_card_vip();
        $this->_data['detail_card_vip'] = $query;
        $this->_data['page_title'] = "CARD VIP";
        $this->display_view('home/user/detail_card_vip');
    }
}